package com.atguigu.spzx.pay.service.Impl;

import com.alibaba.fastjson.JSON;
import com.atguigu.spyx.model.common.com.atguigu.spyx.model.entity.order.OrderInfo;
import com.atguigu.spyx.model.common.com.atguigu.spyx.model.entity.order.PaymentInfo;
import com.atguigu.spzx.pay.mapper.PaymentInfoMapper;
import com.atguigu.spzx.pay.service.PaymentInfoService;
import jakarta.annotation.Resource;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * @author LT
 * @create 2023-11-24-17:47
 */
@Service
public class PaymentInfoServiceImpl implements PaymentInfoService {

    @Resource
    PaymentInfoMapper paymentInfoMapper;

    @Async
    @Override
    public void save(OrderInfo orderInfo, Map<String,String> params) {
        PaymentInfo paymentInfo = new PaymentInfo();
        paymentInfo.setAmount(orderInfo.getTotalAmount());
        paymentInfo.setCallbackTime(new Date());
        paymentInfo.setPaymentStatus(1);

        paymentInfo.setCallbackContent(JSON.toJSONString(params));
        paymentInfo.setContent(params.get("subject"));
        paymentInfo.setPayType(2);
        paymentInfo.setOrderNo(orderInfo.getOrderNo());
        paymentInfo.setUserId(orderInfo.getUserId());
        paymentInfo.setOutTradeNo(params.get("trade_no"));
        paymentInfoMapper.save(paymentInfo);
    }
}
